# coding:utf8
import xml.dom.minidom as minidom
from xml.dom.minidom import Node
from  base64 import *

doc = minidom.parse("ans_k.xml")
texts = []
print 'reading'
f = open("answers.html","w")
i = 1
for node in doc.getElementsByTagName("ans_k"):
    ans_type = node.getElementsByTagName("ans_type")[0].childNodes[0].data
    ans_id = node.getElementsByTagName("ans_id")[0].childNodes[0].data
    ans_text = b64decode(node.getElementsByTagName("ans_txt")[0].childNodes[0].data).decode('gb2312')
    texts.extend(['<p>题型:%s</p>' % ans_type.encode('utf8'),
                  '<p>题库号:%s</p>' % ans_id.encode('utf8') ,
                  '<p>内容:%s</p>' % ans_text.encode('utf8').replace('\n','</br>'),
                 i%5 and '\n' or '''<p><a href='http://blog.ifancc.com'>cracked by fancycode@gmail.com</a>
<a href='http://zjkwuguan.com'>original source is kf2010 database</a>\n</p>'''])
    i+=1

print 'ready to write'
f.write('<html><head><title>题库</title><meta charset="UTF-8" /></head><body>\n')
f.writelines(texts)
f.write('</body></html>\n')
print 'finished reading'
f.close()
print 'press anykey'
raw_input()
    
    
    
    
    
    
    

